import { adjustUploadBatch, showMsg } from '../../../vuex/action'

export default {
  data() {
    return {
      betaname: ''
    }
  },
  vuex: {
    actions: {
      xUploadBatch: adjustUploadBatch,
      xShowMsg: showMsg
    }
  },
  methods: {
    upload() {
      var betaname = this.betaname
      var file = this.$els.file.files[0]
      if (!betaname) {
        return this.xShowMsg({
          type: 'danger',
          content: '请填写组合名称'
        })
      } else if (!file) {
        return this.xShowMsg({
          type: 'danger',
          content: '请先选择Excel文件'
        })
      }
      var formData = new FormData()
      formData.append('betaName', betaname)
      formData.append('excelFile', file)
      this.xUploadBatch(formData)
        .then(() => {
          this.$els.form.reset()
        })
        .catch((res) => {
          // alert(res.error_msg)
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
